package cn.lanqiao.book.dao.impl;

import cn.lanqiao.book.dao.IBaseDao;
import cn.lanqiao.book.dao.ICategoryDao;
import cn.lanqiao.book.pojo.category;

import java.util.List;

public class CategoryDaoImplI extends IBaseDao implements ICategoryDao {

    @Override
    public void addCatefory(category category) {
        String sql = "insert into b_category(c_name) values(?)";
        update(sql, category.getC_name());
    }

    @Override
    public void deleteCategory(String name) {
        String sql = "delete from b_category where c_name = ?";
        update(sql,name);
    }

    @Override
    public List<category> queryAll() {
        String sql = "select * from b_category";
        return queryForList(category.class, sql);
    }

    @Override
    public category queryForOne(String name) {
        String sql = "select * from b_category where c_name = ?";
        return queryForOne(category.class, sql,name);
    }

    @Override
    public void updateCategory(category category) {
        String sql = "update b_category set c_name =? where c_Id = ?";
        update(sql, category.getC_name(),category.getC_id());
    }

    @Override
    public List<category> search(String name) {
        String sql = "select * from b_category where c_name like ?";
        return queryForList(category.class, sql,name);
    }

    @Override
    public category queryForOnebyid(int id) {
        String sql = "select * from b_category where c_id = ?";
        return queryForOne(category.class, sql,id);
    }
}
